package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request/adminRequest"
	"exercise/application/yiran/app/service/admin"
	"github.com/gin-gonic/gin"
)

type studentExamController struct {
}

// PreAllocate 预分配用户
func (*studentExamController) PreAllocate(ctx *gin.Context) {
	request := new(adminRequest.PreAllocateRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewAllotService(ctx).PreAllocate(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "预分配成功")
}

// ClearAllocate 清除学生
func (*studentExamController) ClearAllocate(ctx *gin.Context) {
	request := new(adminRequest.ClearAllocateRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewAllotService(ctx).ClearAllocate(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "清除成功")
}

// AutoExamRoom 自动分配考场
func (*studentExamController) AutoExamRoom(ctx *gin.Context) {
	request := new(adminRequest.AutoExamRoomRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewAllotService(ctx).AutoExamRoom(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

// ExamList 考场列表
func (*studentExamController) ExamList(ctx *gin.Context) {
	request := new(adminRequest.ExamListRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewAllotService(ctx).ExamList(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*studentExamController) AutoFillsEmptyRoom(ctx *gin.Context) {
	request := new(adminRequest.AutoFillsEmptyRoomRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewAllotService(ctx).AutoFillsEmptyRoom(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func NewStudentExamController() *studentExamController {
	return &studentExamController{}
}
